//统一管理咱们项目用户相关的接口

import request from '@/api/index'

//项目用户相关的请求地址
//axios的请求的泛型已经重写<any占位,类型>，直接写<类型>
//登录接口
export const reqLoginAPI = (data: loginFormData) =>
  request.post<loginResponseData>('/api/user/login', data)
//获取用户信息

export const reqUserInfoAPI = () =>
  request.get<userInfoReponseData>('/api/user/info')

//退出登录
export const reqLogoutAPI = () => request.post<{}>('/admin/acl/index/logout')


//定义用户相关数据的ts类型 
//用户登录接口携带参数的ts类型
interface loginFormData {
  username: string
  password: string
}

//定义登录接口返回数据类型
interface loginResponseData {
  token: string
}

//定义获取用户信息返回数据类型
export interface userInfoReponseData {
  routes: string[]
  buttons: string[]
  roles: string[]
  username: string
  avatar: string
}

import { ResPage, User } from "@/api/interface/index";
/**
 * @name 用户管理模块
 */
// 获取用户列表
export const getUserList = (params: User.ReqUserParams) => {
  return request.post<ResPage<User.ResUserList>>("" + `/user/list`, params);
};

// 获取树形用户列表
export const getUserTreeList = (params: User.ReqUserParams) => {
  return request.post<ResPage<User.ResUserList>>("" + `/user/tree/list`, params);
};

// 新增用户
export const addUser = (params: { id: string }) => {
  return request.post("" + `/user/add`, params);
};

// 批量添加用户
export const BatchAddUser = (params: FormData) => {
  return request.post("" + `/user/import`, params);
};

// 编辑用户
export const editUser = (params: { id: string }) => {
  return request.post("" + `/user/edit`, params);
};

// 删除用户
export const deleteUser = (params: { id: string[] }) => {
  return request.post("" + `/user/delete`, params);
};

// 切换用户状态
export const changeUserStatus = (params: { id: string; status: number }) => {
  return request.post("" + `/user/change`, params);
};

// 重置用户密码
export const resetUserPassWord = (params: { id: string }) => {
  return request.post("" + `/user/rest_password`, params);
};

// 导出用户数据
export const exportUserInfo = (params: User.ReqUserParams) => {
  return request.download("" + `/user/export`, params);
};

// 获取用户状态字典
export const getUserStatus = () => {
  return request.get<User.ResStatus[]>("" + `/user/status`);
};

// 获取用户性别字典
export const getUserGender = () => {
  return request.get<User.ResGender[]>("" + `/user/gender`);
};

// 获取用户部门列表
export const getUserDepartment = () => {
  return request.get<User.ResDepartment[]>("" + `/user/department`);
};

// 获取用户角色字典
export const getUserRole = () => {
  return request.get<User.ResRole[]>("" + `/user/role`);
};
